package o;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.cloudservice.CloudAccountManager;
import com.huawei.cloudservice.CloudRequestHandler;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import com.huawei.hwid.core.constants.HwAccountConstants;
import com.huawei.hwid.core.helper.handler.ErrorStatus;

public class cus {

    public interface b {

        public enum d {
            SUCCESSED,
            FAILED,
            INTERRUPT
        }

        a ˋ();

        void ˏ(d dVar);
    }

    public static class a {
        private int ˎ;
        private int ॱ;

        public Bundle ॱ() {
            Bundle bundle = new Bundle();
            bundle.putInt(CloudAccountManager.KEY_LOGIN_CHANNEL, this.ˎ);
            bundle.putInt(CloudAccountManager.KEY_REQCLIENTTYPE, this.ॱ);
            return bundle;
        }

        public a ˊ(int i) {
            this.ˎ = i;
            return this;
        }

        public a ॱ(int i) {
            this.ॱ = i;
            return this;
        }
    }

    static class e extends ccs {
        private b ˏ;

        static class e extends ccs {
            private e() {
            }

            public void onFinish(Bundle bundle) {
                cup.ˊ.ˋ("PhoneBinder", " InstallRequestHandler onFinish");
            }

            public void onError(ErrorStatus errorStatus) {
                if (errorStatus != null) {
                    super.onError(errorStatus);
                    cup.ˊ.ˊ("PhoneBinder", "phoneBinder installHwIDonError, ErrorCode: " + errorStatus.getErrorCode() + ", ErrorReason: " + errorStatus.getErrorReason());
                }
            }

            protected String ˋ() {
                return "initial";
            }
        }

        public e(b bVar) {
            this.ˏ = bVar;
        }

        public void onError(ErrorStatus errorStatus) {
            if (errorStatus != null) {
                int errorCode = errorStatus.getErrorCode();
                cup.ˊ.ˏ("PhoneBinder", "bindPhone CloudRequestHandler onError , errorCode = " + errorCode + ",errorResion=" + errorStatus.getErrorReason());
                super.onError(errorStatus);
                Context ˎ = cuo.ˎ();
                if (34 == errorCode) {
                    CloudAccountManager.initial(ˎ, new Bundle(), new e());
                    this.ˏ.ˏ(d.INTERRUPT);
                    return;
                }
                if (errorCode == 41) {
                    if (cep.ˊ(ˎ, "com.huawei.hwid") && ccq.ˏ(ˎ)) {
                        ced.ˋ(ˎ, "com.huawei.hwid", null, cef.ˎ("com.huawei.hwid_default"));
                        this.ˏ.ˏ(d.INTERRUPT);
                        return;
                    }
                    cup.ˊ.ˎ("PhoneBinder", "bindPhone CloudRequestHandler onError , hwid not installed or  not login");
                }
                if (3002 == errorCode) {
                    this.ˏ.ˏ(d.INTERRUPT);
                    return;
                }
            }
            this.ˏ.ˏ(d.FAILED);
        }

        protected String ˋ() {
            return "getVerifiedPhoneOrEmail";
        }

        public void onFinish(Bundle bundle) {
            if (bundle == null) {
                this.ˏ.ˏ(d.FAILED);
                return;
            }
            String string = bundle.getString(HiAnalyticsConstant.BI_KEY_RESUST, "0");
            cup.ˊ.ˋ("PhoneBinder", "CloudRequestHandler bindPhone finish ,(success:1,fail:0) result = " + string);
            if ("1".equals(string)) {
                CharSequence string2 = bundle.getString("secrityPhoneOrsecrityEmail", "");
                CharSequence string3 = bundle.getString("accountName", "");
                if (TextUtils.isEmpty(string2) && TextUtils.isEmpty(string3)) {
                    cup.ˊ.ˋ("PhoneBinder", "CloudRequestHandler bindPhone finish secrityPhoneOrsecrityEmail or currentPhone is null");
                    this.ˏ.ˏ(d.FAILED);
                    return;
                }
                this.ˏ.ˏ(d.SUCCESSED);
                return;
            }
            this.ˏ.ˏ(d.FAILED);
        }
    }

    public static cus ˋ() {
        return new cus();
    }

    public void ˎ(Context context, b bVar, boolean z) {
        if (context == null) {
            cup.ˊ.ˋ("PhoneBinder", "bindphone error,context is null");
            bVar.ˏ(d.FAILED);
            return;
        }
        Object userId = UserSession.getInstance().getUserId();
        if (TextUtils.isEmpty(userId)) {
            cup.ˊ.ˋ("PhoneBinder", "bindphone error,userid is null");
            bVar.ˏ(d.FAILED);
            return;
        }
        a ˋ = bVar.ˋ();
        Bundle bundle = ˋ == null ? new Bundle() : ˋ.ॱ();
        bundle.putBoolean(HwAccountConstants.EXTRA_ONLY_QUERY, !z);
        CloudRequestHandler eVar = new e(bVar);
        cup.ˊ.ˋ("PhoneBinder", "bindphone start getVerifiedPhoneOrEmail isAutoBindPhone=" + z);
        CloudAccountManager.getVerifiedPhoneOrEmail(context, userId, eVar, bundle);
    }

    public void ˏ(Context context, b bVar) {
        ˎ(context, bVar, true);
    }
}
